<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">

        <form  method="post" enctype="multipart/form-data" action="/"  class="layui-form">

        </form>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename1: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass1: [/(.+){6,12}$/, '密码必须6到12位'],
            repass1: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });
        //先查
        //先查一遍根据id
        var user_id=localStorage.getItem("user_id");
        $.ajax({
            type:"POST",
            url: "/userIdlist",
            data:({
                user_id:user_id
            }),
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data;
                    for (var i = 0; i < lists.length; i++){
                        var html = "";
                        html +=`
              <div class="layui-form-item">
                <label for="user_name" class="layui-form-label">
                    <span class="x-red">*</span>用户的姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name" name="user_name" required="" value="${lists[i].user_name}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>添加姓名
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_personal" class="layui-form-label">
                    <span class="x-red">*</span>个人照
                </label>
                <div class="layui-input-inline">
                    <input type="file" id="user_personal" name="user_personal" value="${lists[i].user_personal}" required="" lay-verify="required"
                           autocomplete="off" class="layui-upload-file">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>上传自己的个人照片
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_card" class="layui-form-label">
                    <span class="x-red">*</span>身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_card" name="user_card" required="" value="${lists[i].user_card}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_head" class="layui-form-label">
                    <span class="x-red">*</span>头像
                </label>
                <div class="layui-input-inline">
                    <input type="file" id="user_head" name="user_head" required="" value="${lists[i].user_head}" lay-verify="required"
                           autocomplete="off" class="layui-upload-file">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>上传自己的头像
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_name_n" class="layui-form-label">
                    <span class="x-red">*</span>账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name_n" name="user_name_n" required="" value="${lists[i].user_name_n}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>输入手机号
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="user_password" name="user_password" required=""  lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                   请输入密码
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_password1" class="layui-form-label">
                    <span class="x-red">*</span>请再次输入密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="user_password1" name="user_password1" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_other" class="layui-form-label">
                    <span class="x-red">*</span> 其他
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_other" name="user_other" required="" value="${lists[i].user_other}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_number" class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_number" name="user_number" required="" value="${lists[i].user_number}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_remarks" class="layui-form-label">
                    <span class="x-red">*</span>备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_remarks" name="user_remarks" required="" required="" value="${lists[i].user_remarks}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_s" class="layui-form-label">
                    <span class="x-red">*</span>说明
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_s" name="user_s" required="" required="" value="${lists[i].user_s}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_s" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                   修改
                </button>
                 <button  onclick="memberup1()" class="layui-btn" >
                    返回
                </button>
            </div>

                    `
                        $('.layui-form').append(html);
                    }
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                console.log(data);
                var fordata = new FormData();
                fordata.append('user_id',localStorage.getItem("user_id"));
                fordata.append('user_name',$('#user_name').val());
                fordata.append('user_card',$('#user_card').val());
                fordata.append('user_name_n',$('#user_name_n').val());
                fordata.append('user_password',$('#user_password').val());
                fordata.append('user_other',$('#user_other').val());
                fordata.append('user_number',$('#user_number').val());
                fordata.append('user_remarks',$('#user_remarks').val());
                fordata.append('user_s',$('#user_s').val());
                fordata.append('user_personal',$('#user_personal')[0].files[0]);
                fordata.append('user_head',$('#user_head')[0].files[0]);
                $.ajax({
                    type:"post",
                    url:"/updatauser",
                    processData: false,
                    contentType: false,
                    cache:false,
                    async: false,
                    data:fordata,
                    success:function(data) {
                        console.log(data);
                        if(data.status==401){
                            alert("熔断开启，系统异常");
                            window.location.href="login.html";
                            return;
                        }
                        if(data.status==200) {
                            alert("修改成功");
                            window.location.href="userlist.html";
                            return;
                        }
                        if(data.status==500) {
                            alert("添加错误");
                            window.location.href="userlist.html";
                            return;
                        }
                        if(data.status==null) {
                            alert("修改异常");
                            window.location.href="userlist.html";
                            return;
                        }
                        if(data.status==20) {
                            layer.alert("重复添加", {icon: 3},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                parent.layer.reload(index);
                            });
                            return;
                        }
                    }
                });
                return false;
            });

    });
function memberup1() {
    window.location.href="userlist.html";
    return;
}
</script>

</body>

</html>
